
<!-- iCheck -->
<script src="js/plugins/iCheck/icheck.min.js"></script>
<!-- Jquery Validate -->
<script src="js/plugins/validate/jquery.validate.min.js"></script>

<script>

    ${script}

</script>
<script>
    $(function() {

        Ladda.bind('#tongyi', {
            callback: function(instance) {
                submitdata(instance)
            }
        })

        $.getJSON({
                    url: bathpath + '/api/v1/dytable',
                    type: 'get',
                    // contentType: "application/json",
                    data: {
                        id: 1000
                    }
                })
                .done(function(data) {
                    if (ajaxdatacheck(data)) {

                        // layout

                        var html = ''
                        var itemHtml

                        $('.dbform_title').html(data.content.title)

                        $(data.content.items).each(function(index, item) {

                            html = rederComponent(item)
                            // console.log('log....... ', html)
                            // debugger
                            // debugger
                            if (index % 2 == 0) {
                                $('.dyform_body .col-lg-6').eq(0).append(html)
                            } else {
                                $('.dyform_body .col-lg-6').eq(1).append(html)
                            }

                        })
                    }
                })
                .fail(function(e) {
                    console.error(e.statusText)
                })
                .always(function() {

                })
    })

    function rederComponent(item) {
        var html = ''
        var validationHtml = ''
        switch (item.type) {
            case 'text':

                // validationScript = "$('.dyform_body').validate({rules: {'" + item.name + "': {required: '" + item.required + "', maxlength: " + item.maxLength + "}}})"
                // console.log(validationScript)
                // if (!item.required && !item.maxLength)
                //     validationHtml = '<label id="max-error" class="error" for="max">' + item.validation_msg + '</label>'

                html += '<div class="form-group"><label>' + item.label + '</label> '
                html += '<input type="email" placeholder="' + item.placeholder + '" name="' + item.name + '" class="form-control"></div>'

                // html += validationHtml

                break;
            case 'icheck':

                break;
            case 'summernote':

                break;
            case 'datepicker':

                break;

            default:
                break;
        }
        return html
    }

    $.mockjax({
        url: bathpath + '/api/v1/dytable',
        contentType: "application/json",
        responseTime: 100,
        responseText: {
            "code": 1,
            "msg": "操作成功",
            "errorMsg": null,
            "content": {
                title: '首页123123123',
                items: [{
                    label: '性别',
                    type: 'icheck',
                    ddtype: 'SEX',
                    comp_config: "{checkboxClass: 'icheckbox_square-green',radioClass: 'iradio_square-green'}"
                }, {
                    label: '出生年月',
                    type: 'datepicker',
                    // ddtype: 'SEX',
                    comp_config: "{todayBtn: 'linked',keyboardNavigation: false,forceParse: false,calendarWeeks: true,autoclose: true}"
                }, {
                    label: '通讯地址',
                    type: 'summernote',
                    // ddtype: 'SEX',
                    comp_config: ""
                }, {
                    name: 'userage',
                    label: '年龄',
                    type: 'text',
                    placeholder: '请输入性别,不能超过100哦',
                    // ddtype: 'SEX',
                    maxLength: '30',
                    comp_config: ""
                }, {
                    name: 'userage',
                    label: '年龄',
                    type: 'text',
                    placeholder: '请输入性别,不能超过100哦',
                    // ddtype: 'SEX',
                    maxLength: '30',
                    comp_config: ""
                }, {
                    name: 'userage',
                    label: '年龄',
                    type: 'text',
                    placeholder: '请输入性别,不能超过100哦',
                    // ddtype: 'SEX',
                    maxLength: '30',
                    comp_config: ""
                }, {
                    name: 'userage',
                    label: '年龄',
                    type: 'text',
                    placeholder: '请输入性别,不能超过100哦',
                    // ddtype: 'SEX',
                    maxLength: '30',
                    comp_config: ""
                }, {
                    name: 'userage',
                    label: '年龄123',
                    type: 'text',
                    placeholder: '123132',
                    // ddtype: 'SEX',
                    maxLength: '30',
                    comp_config: ""
                }, {
                    name: 'userage',
                    label: '年龄',
                    type: 'text',
                    placeholder: '请输入性别,不能超过100哦',
                    validation_msg: 'max value is 30',
                    // ddtype: 'SEX',
                    maxLength: '30',
                    comp_config: "",
                    required: true
                }]
            }
        }
    })

    function submitdata(instance) {
        $.getJSON({
                    url: bathpath + '/api/v1/dytable',
                    type: 'post',
                    contentType: "application/json",
                    data: JSON.stringify({
                        "id": $('#shengji_id').val(),
                        "pwd_safe": $('#shengji_pwd_safe').val(),
                        "level_member": $('#shengji_level_member').val()
                    })
                })
                .done(function(data) {
                    if (ajaxdatacheck(data)) {
                        if (data.code == 1) {
                            swal({
                                title: '升级成功',
                                type: "success"
                            })
                            loadPage('profile.html', '业务中心|fa-drivers-license|profile.html,主页|fa-home|home.html')
                        } else {
                            swal({
                                title: '出错了',
                                text: data.errorMsg || data.msg,
                                type: "warning"
                            })
                        }
                    }
                })
                .fail(function(e) {
                    console.error(e.statusText)
                })
                .always(function() {
                    if (instance)
                        instance.stop();
                })
    }
</script>

<div class="dyform_body">
    <p class="dbform_title"></p>
    <div class="col-lg-6"></div>
    <div class="col-lg-6"></div>
</div>

<div class="workflow_tool">
    <textarea name="" id="" cols="75" rows="5"></textarea><br>
    <button class="btn btn-sm btn-primary ladda-button" data-style="zoom-in" id="tongyi" type="button">确定</button>

    <button class="btn btn-default"> 不同意</button>
</div>